﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.Models;
using System.Collections.Generic;

namespace IdentityServer4.ServerDemo.Helper
{
    /// <summary>
    /// IdentityServer 的配置文件，一般我们需要注册到DI层
    /// </summary>
    /// <remark>
    /// <para/>Author   :  An
    /// <para/>Date     :  2020-02-13
    /// </remark>
    public class Config
    {

        #region 资源
        /// <summary>
        /// 这个APiResource 参数就是我们API
        /// </summary>
        /// <remark>
        /// <para/>Author   :  An
        /// <para/>Date     :  2020-02-13
        /// </remark>
        /// <returns></returns>
        public static IEnumerable<ApiResource> GetResource()
        {
            // An 2020-02-13 [ 资源信息列表 ]
            var resource = new List<ApiResource>()
            {
                new ApiResource("SCAPI","SC Api1")
            };
            return resource;
        }
        #endregion

        #region 客户端

        /// <summary>
        /// 客户端信息
        /// </summary>
        /// <remark>
        /// <para/>Author   :  An
        /// <para/>Date     :  2020-02-13
        /// </remark>
        /// <returns></returns>
        public static IEnumerable<Client> GetClients()
        {
            var clients = new List<Client>()
            {
                new Client()
                {
                    // An 2020-02-13 [ 指定Client(客户端)Id ]
                     ClientId="APEXSCAPI",
                     // An 2020-02-13 [ 授权模式 ClientCredentials:客户端模式 ]
                     AllowedGrantTypes = GrantTypes.ClientCredentials,
                     // An 2020-02-13 [ 指定Client(客户端) Secret ]
                     ClientSecrets={new Secret("APEXSCAPI_Secret".Sha256())},
                     // An 2020-02-13 [ 指定资源范围：允许访问的资源范围，包含但不限于ApiResource中的资源 ]
                     AllowedScopes={ "SCAPI" },
                     // An 2020-02-13 [ 过期时间 ]
                     AccessTokenLifetime = 60*5
                }
            };
            return clients;
        }
        #endregion



    }
}
